package  
{
	import flash.display.Bitmap;
	import starling.core.Starling;
	
	public class BGManager 
	{
		private var mStageWidth:int = 0;
		private var mStageHeight:int = 0;
		private var mImageData:Vector.<uint> = null;
		
		public function BGManager() {}
		
		public function Init(aBitmap:Bitmap):void
		{
			mStageWidth = Starling.current.stage.stageWidth;
			mStageHeight = Starling.current.stage.stageHeight;
			mImageData = new Vector.<uint>(mStageHeight * mStageHeight, true);
			
			var pos:int = 0;
			var width:int = aBitmap.bitmapData.width;
			var height:int = aBitmap.bitmapData.height;
			for (var i:int = 0; i < height; i++)
			{
				for (var j:int = 0; j < width; j++)
				{
					mImageData[pos] = aBitmap.bitmapData.getPixel(j, i);
					pos++;
				}
			}
			
			MAX_POS = pos;
		}
		
		private var MAX_POS:uint = 0;
		public function GetColorAt(aX:int, aY:int):uint
		{
			if (aX < 0 || aX > mStageWidth) 	return 0;
			if (aY < 0 || aY > mStageHeight) 	return 0;
			
			var pos:int = (aY * mStageWidth) + aX;
			if (pos > MAX_POS) return 0;
			return mImageData[pos];
		}
	}
}